export default {
    mounted(el:HTMLElement,binding:any):void{
        binding.dir.task(el,binding.value)
    },
    beforeUpdate(el:HTMLElement,binding:any):void{
        binding.dir.task(el,binding.value)
	},
    task(el:HTMLElement,value:unknown){
        el.style.display=value?'':"none"
        if(!value)return
        const {left,top,height} = (el.parentElement as HTMLElement).getBoundingClientRect()
        const {clientHeight,clientWidth} = document.documentElement
        const oh = el.offsetHeight
        let y=0,h="left";
        if(top+height+oh<=clientHeight||top-oh<=0)
            y = height
        else 
            y = -oh
        if(left+el.offsetWidth>clientWidth)
            h = "right"
        el.style.cssText=`top:${y}px;${h}:0px`
    }
}